class Instr_queue:
    def __init__(self, file_path, reservation_station, reorder_buffer):
        self.file_path = file_path
        self.instructions = self.load_instructions()
        self.reservation_station = reservation_station
        self.reorder_buffer = reorder_buffer
        self.index = 0  # 当前处理的指令索引

    def load_instructions(self):
        """
        从文件中加载指令。
        :return: 指令列表。
        """
        instruction_list = []
        try:
            with open(self.file_path, 'r') as file:
                for line in file:
                    instruction_list.append(line.strip())
        except FileNotFoundError:
            print(f"Error: The file {self.file_path} was not found.")
        except Exception as e:
            print(f"An error occurred: {e}")
        return instruction_list

    def dispatch_instruction(self):
        """
        向保留站和重排序缓冲区分发指令。
        """
        if self.index < len(self.instructions) and not self.reorder_buffer.is_full():
            instruction = self.instructions[self.index]
            operation, destination = instruction.split()[:2]

            # 将指令发送到保留站
            self.reservation_station.issue_instr(instruction)

            # 更新重排序缓冲区
            self.reorder_buffer.add(instruction, destination)
            self.index += 1

    def has_more_instructions(self):
        """
        检查是否还有未处理的指令。
        :return: 布尔值，表示是否还有指令待处理。
        """
        return self.index < len(self.instructions)